package com.zfast.config.vo;

import lombok.Data;

import java.util.List;

@Data
public class PageBean<T> {
    private Integer pageno;  //第几页
    private Integer pagesize; //每页条数
    private List<T> datas;
    private Integer totalno; //总共几页
    private Integer totalsize; //总的条数

    /**
     * 查询回传数据校验
     * @auther zgn
     * @date  2022/5/5
     *
     * @param pageno 默认值1
     * @param pagesize 默认值10
     **/
    public PageBean(Integer pageno, Integer pagesize) {
        if (pageno <= 0) {
            this.pageno = 1;
        } else {
            this.pageno = pageno;
        }
        if (pagesize <= 0) {
            this.pagesize = 10;
        } else {
            this.pagesize = pagesize;
        }
        this.pageno = pageno;
        this.pagesize = pagesize;
    }

    /**
     * 依据数据总数计算'总分页数'
     * @auther zgn
     * @date  2022/5/5
     *
     * @param totalsize 数据总数
     *
     **/
    public void setTotalsize(Integer totalsize) {
        this.totalno = (totalsize % pagesize == 0) ? (totalsize / pagesize) : (totalsize / pagesize + 1);
        this.totalsize = totalsize;
    }
}
